package controllers;

import java.text.SimpleDateFormat;
import java.util.Date;

import models.DonateBook;
import play.mvc.Controller;

public class DonateBooks extends Controller {

	public static void savedbook(String bookname,String author,String address,String stime,String etime,String telphone){
			int state = 0 ;
		try{
			String userid = session.get("userid");
			DonateBook donatebook = new DonateBook () ;
			donatebook.bookname = bookname ;
			donatebook.author = author ;
			donatebook.gaddress = address ;
			 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			 java.util.Date sdateDate = sdf.parse(stime);
			 java.util.Date edateDate = sdf.parse(etime);
			donatebook.starttime =  sdateDate ;
			donatebook.endtime = edateDate ;
			donatebook.telphone = telphone ;
			donatebook.memid = Long.parseLong(userid);
			donatebook.save();
			state = 1 ;
			render(state);
		}catch(Exception e){
			state = 0 ;
			e.printStackTrace();
			render(state);
		}
	}
	
	public static void dontbook(){
		render("/DotBook/dotbook.html");
	}
	
	public static void moredbook(){
		render("/IndexAction/dontbookmore.html");
	}
}
